package com.mlink.ai.chat.ui.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mlink.ai.chat.assistant.robot.R
import com.mlink.ai.chat.constants.KEY_CHAT_EXAMPLE
import com.mlink.ai.chat.ui.activity.ChatActivity
import com.mlink.ai.chat.utils.ChildCategory

class ChildAdapter(var list: List<ChildCategory>) : RecyclerView.Adapter<ChildAdapter.ChildViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChildViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_child_topic, parent, false)
        return ChildViewHolder(view)
    }

    override fun onBindViewHolder(holder: ChildViewHolder, position: Int) {
        holder.tvContent.text = list[position].title
        holder.itemView.setOnClickListener {
            holder.itemView.context.startActivity(Intent(holder.itemView.context, ChatActivity::class.java).apply {
                putExtra(KEY_CHAT_EXAMPLE, list[position].prompt)
            })
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class ChildViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tvContent = itemView.findViewById<TextView>(R.id.tv_content)
    }
}